import { AsyncStorage } from 'react-native';
import type { Action } from './types';

export const SET_USER = 'SET_USER';

export function setUser(user: any): Action {
  console.log('setUser----------')
  return {
    type: SET_USER,
    payload: user,
  };
}

export function login(userName, password) {
  console.log('logining----------')
  return dispatch => {

    let user = { name: userName };
    AsyncStorage.setItem("user", JSON.stringify(user)).then(() => {
      console.log('user------')
      dispatch(setUser(user));
    }).catch(e => { console.log(e) });
  };


}